/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean.CI.Profile;

import entity.Employee;
import javaclass.RedirectProperties;
import javax.faces.event.ActionEvent;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.el.ELContext;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import managedbean.Controller;
import session.stateless.EmployeeBeanLocal;

/**
 *
 * @author Vincent
 */
@ManagedBean(name="viewContactListManagerBean")
@ViewScoped
public class ViewContactListManagerBean implements Serializable{
    @EJB 
    private EmployeeBeanLocal employeeBeanLocal; 
    private Employee selectedEmployee;
    private Employee employee;
    private String statusMessage;
    /** Creates a new instance of PositionDataTableBean */
    
    public ViewContactListManagerBean() {
    }

    public List<Employee> retrieveContactList() { 
        List<Employee> temp=employee.getContactList();
        return employee.getContactList(); 
    }

    public Employee getSelectedEmployee() {
        return selectedEmployee;
    }
    public void setSelectedEmployee(Employee selectedEmployee) {
        this.selectedEmployee = selectedEmployee;
    }
    
    public void initView(PhaseEvent event){
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        Controller controller = (Controller) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "controller");
        this.employee = controller.getEmployee();
    }

    public void removeContactList(ActionEvent event){
        employee.getContactList().remove(selectedEmployee);
        employeeBeanLocal.removeContactList(employee.getEmployeeId(), selectedEmployee.getEmployeeId());
        RedirectProperties rp = new RedirectProperties();
        try{
            FacesContext.getCurrentInstance().getExternalContext().redirect("viewContactList.xhtml");
        }
        catch (Exception e){
            
        }
        statusMessage = "Remove employee " + selectedEmployee.getEmployeeName() + " from contact list successfully"; 
 
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Remove Contact List Result: " +statusMessage + "", ""));
    }    
}
